package algorithms.que13;

import edu.princeton.cs.algs4.Stack;

/**
 * @功能
 * @创建时间 2020/7/7
 */
public class EvaluatePostfix {
    public static void main(String[] args) {
     String s= "12+34-*56-*";
        Stack<String> a = new Stack<>();
        Stack<String> b = new Stack<>();
        char[] c= s.toCharArray();
        for(char d:c){
            String e = String.valueOf(d);
            if(e.equals("+")){
                 String val = String.valueOf(Double.valueOf(b.pop())+Double.valueOf(b.pop()));
                 b.push(val);
            }else if(e.equals("-")){
                String val = String.valueOf(Double.valueOf(b.pop())-Double.valueOf(b.pop()));
                b.push(val);
            }else if(e.equals("*")){
                String val = String.valueOf(Double.valueOf(b.pop())*Double.valueOf(b.pop()));
                b.push(val);
            }
            else if(e.equals("/")){
                String val = String.valueOf(Double.valueOf(b.pop())/Double.valueOf(b.pop()));
                b.push(val);
            }else {
                b.push(e);
            }
        }
        System.out.println(b.peek());
    }
}
